package com.happy.table;

import cn.hutool.json.JSONObject;

import java.util.List;

/**
 * @Author : Yan
 * @Description : 表格 tr
 */
public class Tr {

    // tr替换字符串
    private String trReplcae = TableReplace.TR.getValue();

    // trHtml
    private String trHtml = "<tr> \n" + this.trReplcae + "</tr> \n";

    public Tr(JSONObject jsonObject, List<Filed> filedList) {
        String tdContent = "";
        // 循环字段列
        for (int i = 0; i < filedList.size(); i++) {
            Filed filed = filedList.get(i);
            // 获取指定列的数据
            String tdValue = jsonObject.get(filed.getFiled()).toString();
            // 创建一个td实例
            Td td = new Td(tdValue);
            tdContent += td.getTdHtml();
        }
        this.trHtml = this.trHtml.replace(this.trReplcae, tdContent);
    }

    public Tr(List<Filed> filedList) {
        String thContent = "";
        // 循环遍历标题
        for (Filed filed : filedList) {
            // 创建一个td实例
            Th th = new Th(filed.getTitle());
            thContent += th.getThHtml();
        }
        this.trHtml = this.trHtml.replace(this.trReplcae, thContent);
    }

    // 获取trHtml
    public String getTrHtml() {
        return this.trHtml;
    }

}
